import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jinke/utils/util.dart';

class ProOpenStep3Cell extends StatelessWidget {
  const ProOpenStep3Cell({
    Key? key,
    this.isFirst = false,
    this.isLast = false,
    required this.title,
    this.rightTitle,
    this.content,
    this.onChange,
  }) : super(key: key);
  final bool isFirst;
  final bool isLast;
  final String title;
  final String? rightTitle;
  final String? content;
  final Function(DateTime)? onChange;
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(16.r, 0, 16.r, 0),
      width: Get.width,
      child: Row(
        children: [
          Container(
            height: 116.r,
            child: Column(
              children: [
                Container(
                  color: isFirst ? ColorsUtil.bg : ColorsUtil.content,
                  width: 0.5,
                  height: 50.r,
                ),
                _getIcon(),
                Visibility(
                  visible: !isLast,
                  child: Container(
                    color: isLast ? ColorsUtil.bg : ColorsUtil.content,
                    width: 0.5,
                    height: 50.r,
                  ),
                ),
              ],
            ),
          ),
          Expanded(
            child: Container(
              height: 100.r,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(4.r),
              ),
              margin: EdgeInsets.fromLTRB(16.r, 0, 0, 16.r),
              padding: EdgeInsets.symmetric(horizontal: 16.r, vertical: 20.r),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        title,
                        style:
                            TextStyle(color: ColorsUtil.title, fontSize: 15.sp),
                      ),
                      Text(
                        rightTitle ?? '',
                        style:
                            TextStyle(color: ColorsUtil.title, fontSize: 15.sp),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 10.r,
                  ),
                  InkWell(
                    onTap: () {
                      showModalBottomSheet(
                        // 底部颜色为透明，用Container修饰顶部圆角
                        backgroundColor: Colors.transparent,
                        isScrollControlled: true,
                        context: context,
                        builder: (BuildContext content) {
                          return SingleChildScrollView(
                            child: Container(
                              padding: EdgeInsets.only(top: 20.sp),
                              clipBehavior: Clip.antiAlias,
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.only(
                                  topLeft: const Radius.circular(20.0),
                                  topRight: const Radius.circular(20.0),
                                ),
                              ),
                              child: Column(
                                children: [
                                  BrnCalendarView(
                                    showControllerBar: true,
                                    displayMode: DisplayMode.month,
                                    selectMode: SelectMode.single,
                                    dateChange: (date) {
                                      if (onChange != null) {
                                        onChange!(date);
                                      }
                                    },
                                  ),
                                  SafeArea(
                                    child: Container(
                                      margin: EdgeInsets.only(
                                          top: 10.sp, bottom: 5.sp),
                                      width: Get.width / 5 * 4,
                                      child: ElevatedButton(
                                        onPressed: () {
                                          Get.back();
                                        },
                                        style: ElevatedButton.styleFrom(
                                          primary: Color(0xff58C165),
                                          shape: StadiumBorder(),
                                        ),
                                        child: Text("确定"),
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          );
                        },
                      );
                    },
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          '计划完成日期：${content ?? '请点击选择'}',
                          style: TextStyle(
                            color: content != null
                                ? ColorsUtil.title
                                : ColorsUtil.content,
                            fontSize: 14.sp,
                          ),
                        ),
                        Icon(
                          Icons.arrow_forward_ios_rounded,
                          color: ColorsUtil.content,
                          size: 12.r,
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _getIcon() {
    return Icon(
      Icons.access_time,
      color: ColorsUtil.content,
      size: 16.r,
    );
  }
}
